package lsy.Servlet;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lsy.tools.AuthFilter;
import lsy.entity.ValidateCode;

import java.io.OutputStream;
import java.io.IOException;


public class ValidateCodeServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession(true);

        ValidateCode coder = new ValidateCode();
        session.setAttribute(AuthFilter.excludeString, coder.getCodeString());
        response.setContentType("image/png");
        try (OutputStream output = response.getOutputStream()) {
            coder.outputCodeImage(output);
        }
    }

}

